package com.health.listener;


import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * pub/sub发布订阅模式-只要消息队列绑定了相同的交换机,消费者即可从消息队列中取到消息
 * 交换机类型:FANOUT
 */
@Component
public class Listener3 {

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(value = "message.queue4"),
                    exchange = @Exchange(value = "fanout.exchange",
                            type = ExchangeTypes.FANOUT)
            )
    )
    public void listener1(String msg){
        System.out.println("1号消费者接收到消息>>"+msg);
    }

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(value = "message.queue5"),
                    exchange = @Exchange(value = "fanout.exchange",
                    type = ExchangeTypes.FANOUT)
            )
    )
    public void listener2(String msg){
        System.out.println("2号消费者接收到消息++"+msg);
    }
}
